<?php

class Eleven_Model_Qzintroduction extends CMS_Model_Abstract
{
	
	public function getIntroduction()
	{
		return $this->getResource('Qzintroduction')->getIntroduction();
	}	
	
    public function saveEdit($post)
	{
		$form = $this->getForm('qzintroductionEdit');
       	return $this->_save($form, $post);
	}
	
    protected function _save($form, $info, $defaults=array())
    {       
        if (!$form->isValid($info)) {
            return false;
        }

        $data = $form->getValues();
        $introduction = $this->getIntroduction();
        
        $fullFilePath1 = $form->pic1->getFileName();
		if($fullFilePath1)
		{
			$introduction->filepath = $this->_thumb($fullFilePath1);
		}
		
       	$introduction->members = $data['members'];
        $introduction->content = $data['content'];
        $introduction->views = $data['views'];
        $introduction->createdate = $data['createdate'];
        $introduction->type = $data['type'];
                
        $introduction->save();
    }
    
 	private function _thumb($fullFilePath)
    {
        $locationFile = $fullFilePath;
        $ext=end(explode(".",$locationFile));
        $currentMicroTime = Internim_Date::getMicrotime();
        $nameFile = $currentMicroTime.'.'.$ext;
        $fullPathNameFile = './data/uploads/qzintroduction/'.$nameFile;
        
        $filterRename = new Zend_Filter_File_Rename(array('target'=> $fullPathNameFile, 'overwrite' => true));
        $filterRename->filter(iconv('UTF-8', 'GB2312', $locationFile));
        
        $target = $filterRename->getFile();
        
    	require_once '../library/phpthumb/ThumbLib.inc.php';  
    	
        $thumb = PhpThumbFactory::create($fullPathNameFile);  
        $thumb->resize(208, 142)->save($fullPathNameFile);
        
        return $fullPathNameFile;
    }
}

?>